/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_STL_AUTO_AUTH_FUNCTIONS_H__
#define __XOS_STL_AUTO_AUTH_FUNCTIONS_H__

namespace xos_auth
{
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 
	// 是否有修改增、删、改、查的权限
	// 

    inline bool can_modify_add( int want, int visitor, int gate )
    {
        bool bRet = false;
        if( !bRet && ( want > 0 ) && ( want < visitor ) && ( want >= gate ) )
        {
            bRet = true;
        }
        return bRet;
    }

    inline bool can_modify_read( int want, int visitor, int gate )
    {
        bool bRet = false;
        if( !bRet && ( want > 0 ) && ( want < visitor ) && ( want >= gate ) )
        {
            bRet = true;
        }
        return bRet;
    }

    inline bool can_modify_modify( int want, int visitor, int gate )
    {
        bool bRet = false;
        if( !bRet && ( want > 0 ) && ( want < visitor ) && ( want >= gate ) )
        {
            bRet = true;
        }
        return bRet;
    }

    inline bool can_modify_delete( int want, int visitor, int gate )
    {
        bool bRet = false;
        if( !bRet && ( want > 0 ) && ( want < visitor ) && ( want >= gate ) )
        {
            bRet = true;
        }
        return bRet;
    }

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 
	// 是否有增、删、改、查权限
	// 

    inline bool can_add( int visit_uid, int visitor_auth, int gate_uid, int gate_auth )
    {
        bool bRet = false;
        if( !bRet && ( visit_uid > 0 ) && ( visit_uid == gate_uid ) )
        {
            bRet = true;
        }
        if( !bRet && ( visitor_auth > gate_auth ) )
        {
            bRet = true;
        }
        return bRet;
    }

    inline bool can_read( int visit_uid, int visitor_auth, int gate_uid, int gate_auth )
    {
        bool bRet = false;
        if( !bRet && ( visit_uid > 0 ) && ( visit_uid == gate_uid ) )
        {
            bRet = true;
        }
        if( !bRet && ( visitor_auth >= gate_auth ) )
        {
            bRet = true;
        }
        return bRet;
    }

	inline bool can_modify( int visit_uid, int visitor_auth, int gate_uid, int gate_auth )
	{
		bool bRet = false;
		if( !bRet && ( visit_uid > 0 ) && ( visit_uid == gate_uid ) )
		{
			bRet = true;
		}
		if( !bRet && ( visitor_auth > gate_auth ) )
		{
			bRet = true;
		}
		return bRet;
	}

    inline bool can_delete( int visit_uid, int visitor_auth, int gate_uid, int gate_auth )
    {
        bool bRet = false;
        if( !bRet && ( visit_uid > 0 ) && ( visit_uid == gate_uid ) )
        {
            bRet = true;
        }
        if( !bRet && ( visitor_auth > gate_auth ) )
        {
            bRet = true;
        }
        return bRet;
    }
}

#endif // __XOS_STL_AUTO_AUTH_FUNCTIONS_H__
